package solution;

import java.util.ArrayList;
import java.util.List;

class Solution {
    /**
     * 2824. 统计和小于目标的下标对数目
     * https://leetcode.cn/problems/count-pairs-whose-sum-is-less-than-target/description/?envType=daily-question&envId=2023-11-24
     * @param
     * @param
     * @return
     */
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(-1);
        list.add(1);
        list.add((2));
        list.add(3);
        list.add(1);
        int x = countPairs(list, 2);
        System.out.println(x);
    }
    public static int countPairs(List<Integer> nums, int target) {
        int len = nums.size();
        int count = 0;
        for(int i = 0; i < len; i++){
            int x = nums.get(i);
            for(int j = i + 1; j < len; j++) {
                int y = nums.get(j);
                if(x + y < target) {
                    count++;
                }
            }
        }
        return count;
    }
    /**
     * 118. 杨辉三角
     * https://leetcode.cn/problems/pascals-triangle/description/
     */
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<List<Integer>>();
        //动态规划
        for(int i = 0; i < numRows; i++) {
            List<Integer> row = new ArrayList<>();
            for(int j = 0; j <= i; j++) {
                if(j == 0 || j ==i) {
                    row.add(1);
                } else {
                    row.add(ret.get(i - 1).get(j - 1) + ret.get(i - 1).get(j));
                }
            }
            ret.add(row);
        }
        return ret;
    }

    /**
     * 66. 加一
     * https://leetcode.cn/problems/plus-one/description/
     * @param digits
     * @return
     */
    public int[] plusOne(int[] digits) {
        int len = digits.length;
        for(int i = len - 1; i >= 0; i--) {
            if(digits[i] != 9) {
                digits[i]++;
                return digits;
            } else {
                //digits[i] == 9
                digits[i] = 0;
            }
        }
        int[] result = new int[len + 1];
        result[0] = 1;
        return result;
    }
}